package org.example.controller;

import org.example.entity.CommonResult;
import org.example.entity.Recite;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.example.service.ReciteService;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/recite")
public class ReciteController {

    @Resource
    ReciteService reciteService;

    @RequestMapping("/getRecited")
    public CommonResult getRecitedPoem(@RequestParam("userId") Long userId){
        List<Recite> recitedPoem = reciteService.getRecitedPoem(userId);
        if (recitedPoem!=null){
            return new CommonResult(200,"success",recitedPoem);
        }
        return new CommonResult(400,"error",null);
    }

    @RequestMapping("/getUnRecited")
    public CommonResult getUnRecitedPoem(@RequestParam("userId") Long userId){
        List<Recite> recitedPoem = reciteService.getUnRecitedPoem(userId);
        if (recitedPoem!=null){
            return new CommonResult(200,"success",recitedPoem);
        }
        return new CommonResult(400,"error",null);
    }

    @RequestMapping("/isRecite")
    public CommonResult isRecite(@RequestParam("userId") Long userId,
                                 @RequestParam("poemId") Long poemId) {

        return new CommonResult(200,"success",reciteService.isRecite(userId,poemId));
    }

    @RequestMapping("/addRecite")
    public CommonResult addRecite(@RequestBody Recite recite){
        if (reciteService.addRecite(recite)){
            return new CommonResult(200,"success",null);
        }
        return new CommonResult(400,"error",null);
    }

    @RequestMapping("/deleteRecite")
    public CommonResult deleteRecite(@RequestParam("userId") Long userId,
                                     @RequestParam("poemId") Long poemId){
        if (reciteService.deleteRecite(userId,poemId)){
            return new CommonResult(200,"success",null);
        }
        return new CommonResult(400,"error",null);
    }

    @RequestMapping("/updateRecite")
    public CommonResult updateRecite(@RequestBody  Recite recite){
        if (reciteService.updateRecite(recite)){
            return new CommonResult(200,"success",null);
        }
        return new CommonResult(400,"error",null);
    }

    @RequestMapping("/isRecited")
    public CommonResult isRecited(@RequestParam("userId") Long userId,
                                  @RequestParam("poemId") Long poemId){

        return new CommonResult(200,"success",reciteService.isRecited(userId,poemId));
    }


}

